/*
  ID: nemokin1
  PROG: concom
  LANG: C++
*/
#include <vector>
#include <list>
#include <assert.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <fstream>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

int rr[101][101];
int visited[101][101];
const int N = 101;

void dfs(int i, int j)
{
    //cout<<"dfs:"<<i+1<<" "<<j+1<<endl;
    
    // 如果i控制j已知，则返回
    if(visited[i][j]) return;
    visited[i][j] = 1;
    // i控制了j，把j的所有股份都加到i中
    for(int k = 0; k < N; k++){
	rr[i][k]+=rr[j][k];
    }
    // i的控制者现在控制了j
    for(int k = 0; k < N; k++){
	if(visited[k][i]){
	    dfs(k,j);
	}
    }
    // 如果i控制了更多的公司，则递归
    for(int k = 0; k < N; k++){
	if(rr[i][k] > 50){
	    dfs(i,k);
	}
    }
}

int main() {
    freopen("concom.in","r",stdin);freopen("concom.out","w",stdout);
    memset(visited,0,sizeof(visited));
    memset(rr,0,sizeof(rr));
    int n;
    
    cin >> n;
    for(int i = 0; i < n; i++){
	int i,j,k;
	cin >> i >> j >> k;
	rr[i-1][j-1] = k;
    }
    for(int i = 0; i < N; i++){
	for(int j = 0; j < N; j++){
	    if(rr[i][j] > 50) {dfs(i,j);}
	}
    }
    for(int i = 0; i <  N; i++){
	for(int j = 0; j < N; j++){
	    if(i == j) continue;
	    if(visited[i][j]) cout << i+1 << " " << j+1 << endl;
	}
    }
    exit(0);
}

